<?php
namespace Admin\Controller;

class CommentController extends PublicController
{
	public function index(){
		$this->assign('title','评论管理列表');
		$this->con();
		$this->display('Comment/index');
	}
	public function con(){
		$con=M('comment')
				// ->fetchSql(true)
				->field('c.id,c.c_content,c.com_time,c.status,a.title,u.name')
				->table('hx_comment c,hx_article a,hx_user u')
				->where('u.id=c.user_id AND a.id=c.art_id')
				->order('id desc')
				->select();
				// dump($con);
		$this->assign('comment',$con);
	}
	//评论状态切换
	public function status(){
		// $this->ajaxReturn($_GET['id']);
		//判断 有无传递ID
		if (empty($_GET['id'])) {
			$this->redirect('Comment/index','空','11111');
			exit;
		}
		$id= I('get.id/d');

		if($id ==0){
			$this->redirect('Comment/index','ddsfsdf','342434');
		}else{
			$data =M('Comment')->field('status')->find($id);
			$status=$data['status'] =='0'?'1':'0';
			$where['id'] = $id;
			$save['status']  = $status;

			$pbc =M('Comment')->where($where)->save($save);
			// $this->redirect('Comment/index','成功屏蔽','3');
			
		}
	}
	//删除评论
	public function del(){
		// $this->ajaxReturn($_GET['id']);
		// exit;
		if (empty($_GET['id'])) {
			
			ajaxReturn($User->getError());
			exit;
		}
		
		$id=I('get.id/d');
		var_dump($id);
		
		if ($id==0) {
			
			ajaxReturn($User->getError());
			exit;
			
		}else{
			
			$delcom=M('Comment');//实例化对象
			$where['id']=$id;
			$delcom->where($where)->delete();

			// $this->redirect('Comment/index');
		}
	}

}